# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Holger Jaekel <holger.jaekel@gmx.de>
pkgname=tiledb
pkgver=2.17.4
pkgrel=1
pkgdesc="Engine for storing and accessing dense and sparse multi-dimensional arrays"
url="https://tiledb.com/"
# Tests fail on s390x
# doesn't build on 32-bit
arch="all !armhf !armv7 !x86 !s390x"
license="MIT"
makedepends="
	abseil-cpp-dev
	blosc-dev
	bzip2-dev
	capnproto-dev
	catch2-3
	clang
	cmake
	crc32c-dev
	curl-dev
	doxygen
	file-dev
	google-cloud-cpp-dev
	libpng-dev
	lz4-dev
	nlohmann-json
	openssl-dev
	samurai
	spdlog-dev
	zlib-dev
	zstd-dev
	"
subpackages="
	$pkgname-dev
	"
source="tiledb-$pkgver.tar.gz::https://github.com/TileDB-Inc/TileDB/archive/refs/tags/$pkgver.tar.gz
	https://raw.githubusercontent.com/muellan/clipp/v1.2.3/include/clipp.h
	00-snake_case.patch
	10-capnproto.patch
	30-versions.patch
	40-catch.patch
	50-magic.patch
	60-clipp.patch
	70-crc32c.patch
	80-stringstream.patch
	90-avx2.patch
	"
builddir="$srcdir/TileDB-$pkgver"

# secfixes:
#   2.17.4-r0:
#     - CVE-2023-5129

# Optional dependencies aws-* are not available on s390x and ppc64le
_with_s3="OFF"
case "$CARCH" in
arm*|s390x|ppc64le) ;;
*)
	makedepends="$makedepends aws-crt-cpp-dev aws-sdk-cpp-dev"
	_with_s3="ON"
	;;
esac

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	CC=clang \
	CXX=clang++ \
	CXXFLAGS="$CXXFLAGS -Wno-deprecated-declarations" \
	LDFLAGS="$LDFLAGS -Wl,--copy-dt-needed-entries" \
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_SKIP_RPATH=ON \
		-DTILEDB_SUPERBUILD=OFF \
		-DTILEDB_VERBOSE=OFF \
		-DTILEDB_HDFS=OFF \
		-DTILEDB_S3=$_with_s3 \
		-DTILEDB_AZURE=OFF \
		-DTILEDB_GCS=ON \
		-DTILEDB_SERIALIZATION=ON \
		-DTILEDB_TOOLS=OFF \
		-DTILEDB_WERROR=OFF \
		-DTILEDB_CPP_API=ON \
		-DTILEDB_STATS=ON \
		-DTILEDB_STATIC=OFF \
		-DTILEDB_TESTS="$(want_check && echo ON || echo OFF)" \
		-DTILEDB_CCACHE=OFF \
		-DTILEDB_ARROW_TESTS=OFF \
		-DTILEDB_CRC32=ON \
		-DTILEDB_WEBP=OFF \
		-DTILEDB_FORCE_ALL_DEPS=OFF \
		$CMAKE_CROSSOPTS

	# compile Cap’n Proto schema with the current version
	cd "$builddir/tiledb/sm/serialization"
	capnp compile -oc++:posix tiledb-rest.capnp
	cd "$builddir"

	cmake --build build
	if want_check; then
		cmake --build build --target tests
	fi
}

check() {
	ctest --output-on-failure --test-dir build \
		-R '^unit_|test_assert' -E 'unit_capi_query_plan'
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
0660a2c72398efdce22028a6c8d6490f0d42f8969f4d74cb4f30862580d716e9991e1fb8b1d3581509bc37ad3be7ed08290ae743e377fd58ab3ce8274f7561ea  tiledb-2.17.4.tar.gz
0a801eff46581a96e571b41ce734d5a8e7f30333d46e3fb81c4c40fc44c18035d4b4597732221e37945ad23b94e53e496562ae4b24d358761dbf5ed803f66ff4  clipp.h
6947a7ccc7365a4f8066198b7df96af3a9a109e5c0628910910456f6168ebe96b7a8c91b505cdb81320f8eac3311b6e2e95e5a1be101d86037d90820d9be042a  00-snake_case.patch
5b94967fd2de48b113669a41c515a0e99dd398d2f8db2b0532e2dd852071c02f0a4a19efa183017c2a7d163e2d16b2e25bf195f4313aaeeb8f95e7ef505dec38  10-capnproto.patch
ef83c2568a3ec826d4cf03fd2b40d7420568457bca5dc2a78651ecc25c76c84d6fa9ed2e54bd91764d6fa490e89fb5972772a01f210fdac212af2f6eae22d472  30-versions.patch
761af7bd08be2b7751dd68b4c6e7214afa484f4f1ae3956f00bc2014acc52f9cb6b184e1e13239fb38cb349698efd88ba511f79d182eaa4fc075ac450b1f8940  40-catch.patch
3067c9cf694a9a8a1847970d77b6402906617b3cf98598305b5d31f891db6f3a84c88951ae7addbd51ae8aae160845d28942179a70b9db3df483f57700f45a38  50-magic.patch
9a6a4130b60b6e6e71b30e87ffdefc830a3dbce1ed484cee872d470556bb06db68817fd8d48211c7301f96a4cbc7564295557a8390b451d316362a459e4ab794  60-clipp.patch
a6bb9f16ca2427a3a59fc697108710b09dd7d74ebe78b5baa5e152fd016cb05c8e09174d17eb8433c6fc4783c34d2c7f740386c2c16c963b4ce4c7bfcba4519f  70-crc32c.patch
13458544cd274e7dba08dd1804ec8f97450a72d1486b1ce4792617c8c38a413d7500043eb82ee9307ef6635316e86e8df9935be27ea8beb93980c7ab03ef4061  80-stringstream.patch
ad8a8e5f030327d82336dd1087bff40f9cf7a4bce204049ffec95a7e76d72d3d68ae1a0ae973be89f6cdecdfd15549a93575659b611cfce807970d28dcbc7e0f  90-avx2.patch
"
